package com.bbx.taxi.client.Activity.Address;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import butterknife.InjectView;

import com.bbx.taxi.official.R;
import com.bbx.taxi.client.Activity.ContactPersonActivity;
import com.bbx.taxi.client.Activity.Base.BaseBBXActivity;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Bean.Extra.AddressMsg;
import com.bbx.taxi.client.Fragment.CarpoolingFragment;

/**
 * 添加不同地点上下车
 */ 
public class AddDifferentAddressActivity extends BaseBBXActivity {
	public static final int SETOUT_REQUEST_CODE = 2;
	public static final int DESTINATION_REQUEST_CODE = 3;
	public static final int RESULT_CODE=1;
	@InjectView(R.id.telephonelayout)LinearLayout telephonelayout;
	@InjectView(R.id.setoutlayout)LinearLayout setoutlayout;
	@InjectView(R.id.destinationlayout)LinearLayout destinationlayout;
	@InjectView(R.id.telephone)TextView telephone;
	@InjectView(R.id.setout)TextView setout;
	@InjectView(R.id.destination)TextView destination;
	@InjectView(R.id.confirm)Button confirm;
	private String tel;//电话
	private String name;//联系人
	private String setout_longitude;//出发地地址经度
	private String setouts_latitude;//出发地地址纬度
	private String setout_address;//出发地
	private String destination_longitude;//目的地地址经度
	private String destination_latitude;//目的地地址纬度
	private String destination_address;//目的地

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.adddifferentaddress);
		super.onCreate(savedInstanceState);
		setTitle("不同地点上车/下车");
	}
	
	@Override
	protected void initView() {
		// TODO Auto-generated method stub
		telephonelayout.setOnClickListener(this);
		setoutlayout.setOnClickListener(this);
		destinationlayout.setOnClickListener(this);
		confirm.setOnClickListener(this);
	}

	@Override
	protected void initData() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.telephonelayout:
			startActivityForResult(
					new Intent(this, ContactPersonActivity.class),
					MainAttribute.REQUEST_CODE_PERSON);
			break;
		case R.id.setoutlayout:
			startActivityForResult(new Intent(this, EditAddressActivity.class).putExtra(AddressMsg.extra_editaddress, AddressMsg.ADDRESS_COLLECT),
					SETOUT_REQUEST_CODE);
			break;
		case R.id.destinationlayout:
			startActivityForResult(new Intent(this, EditAddressActivity.class).putExtra(AddressMsg.extra_editaddress, AddressMsg.ADDRESS_COLLECT)
					,
					DESTINATION_REQUEST_CODE);
			break;
		case R.id.confirm:
			Bundle bundle=new Bundle();
			bundle.putString("setout_longitude",setout_longitude);
			bundle.putString("setouts_latitude",setouts_latitude);
			bundle.putString("setout_address",setout_address);
			bundle.putString("destination_longitude",destination_longitude);
			bundle.putString("destination_latitude",destination_latitude);
			bundle.putString("destination_address",destination_address);
			bundle.putString("name",name);
			bundle.putString("tel",tel);
			Intent intent=new Intent();
			intent.putExtras(bundle);
			setResult(DifferentAddressActivity.RESULT_CODE,intent);   
			finish();
			overridePendingTransition(0, R.anim.base_slide_right_out);
			break;
			default:
				super.onClick(v);
				
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (resultCode) {
		case MainAttribute.REQUEST_CODE_PERSON:
			if (data != null) {
				name = data.getStringExtra("name");
				tel = data.getStringExtra("telephone");
				if (name != null && tel != null && !name.equals("")
						&& !tel.equals("")) {
					telephone.setText(name + (tel.replace("+86", "")));
				}
			}
			break;
		case RESULT_CODE:
			switch(requestCode){
			case SETOUT_REQUEST_CODE:
				if (data != null) {
					setout_address = data.getStringExtra("address_name");
					setout_longitude = data.getStringExtra("address_longitude");
					setouts_latitude = data.getStringExtra("address_latitude");
					if (!setout_address.equals("")&& !setout_longitude.equals("")&&!setouts_latitude.equals("")) {
						setout.setText(setout_address);
					}
				}
				break;
			case DESTINATION_REQUEST_CODE:
				if (data != null) {
					destination_address = data.getStringExtra("address_name");
					destination_longitude = data.getStringExtra("address_longitude");
					destination_latitude = data.getStringExtra("address_latitude");
					if (!destination_address.equals("")&& !destination_longitude.equals("")&&!destination_latitude.equals("")) {
						destination.setText(destination_address);
					}
				}
				break;
			}
			break;
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	

	@Override
	protected void desotryItems() {
		// TODO Auto-generated method stub
		
	}
}
